package com.sharding.shardingdemo.controller;

import com.alibaba.druid.sql.PagerUtils;
import com.sharding.shardingdemo.entity.UserMsg;
import com.sharding.shardingdemo.service.UserMsgService;
import com.sharding.shardingdemo.utils.PageUtils;
import com.sharding.shardingdemo.utils.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 
 *
 * @author zjmm zjmm@gmail.com
 * @since 1.0.0 2022-08-16
 */
@RestController
@RequestMapping("user/msg")
public class UserMsgController {
    @Autowired
    private UserMsgService userMsg1Service;

        @PostMapping("/save")
        public ResultData save(@RequestBody UserMsg dto){
        //效验数据
            userMsg1Service.save(dto);
            return ResultData.SUCCESS();
        }


        @GetMapping("/list")
        public ResultData list(@RequestParam Map<String,Object> map){
        //效验数据
            List<UserMsg> list = userMsg1Service.list();
            return ResultData.SUCCESS().success(list);
        }

         @GetMapping("/page")
        public ResultData page(@RequestParam Map<String,Object> map){
        //效验数据
            PageUtils page = userMsg1Service.queryPage(map);
            return ResultData.SUCCESS().success(page);
        }

        @PutMapping("/update")
        public ResultData update(@RequestBody UserMsg dto){
            userMsg1Service.removeById(dto.getId());
            userMsg1Service.save(dto);
            return ResultData.SUCCESS();
        }

        @DeleteMapping("/del/{id}")
        public ResultData delete(@PathVariable("id") String id){

            userMsg1Service.removeById(id);

            return ResultData.SUCCESS();
        }


}